package com.yanqu.road.entity.activity.peakstronghold.config;

import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.utils.string.StringUtils;
import org.apache.bcel.generic.PUSH;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@FieldTypeAnnotation(tableName = "t_s_activity_peak_hold_time")
public class PeakStrongholdTimeConfig {
    @FieldTypeAnnotation(select = true)
    private int activityId;
    @FieldTypeAnnotation
    private int timeId;
    @FieldTypeAnnotation
    private int type;
    @FieldTypeAnnotation
    private int beginTime;
    @FieldTypeAnnotation
    private int durationTime;
    @FieldTypeAnnotation
    private String param;

    @FieldTypeAnnotation(desc = "排名积分获得1;30|2;28|3;26|6;24|11;20|21;15|100;10")
    private String score;

    private List<PeakStrongholdRankScore> scoreList;

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public int getTimeId() {
        return timeId;
    }

    public void setTimeId(int timeId) {
        this.timeId = timeId;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(int beginTime) {
        this.beginTime = beginTime;
    }

    public int getDurationTime() {
        return durationTime;
    }

    public void setDurationTime(int durationTime) {
        this.durationTime = durationTime;
    }

    public String getParam() {
        return param;
    }

    public void setParam(String param) {
        this.param = param;
    }

    public int getEndTime() {
        return beginTime + durationTime;
    }

    public String getScore() {
        return score;
    }

    public void setScore(String score) {
        this.score = score;
        if("0".equals(score)){
            return;
        }
        scoreList = new ArrayList<>();
        String[] scoreMapStrs = score.split("\\|");
        for (String scoreMapStr : scoreMapStrs) {
            List<Integer> scoreAttr = StringUtils.stringToIntegerList(scoreMapStr, ";");
            PeakStrongholdRankScore rankScore = new PeakStrongholdRankScore();
            rankScore.setRank(scoreAttr.get(0));
            rankScore.setScore(scoreAttr.get(1));
            scoreList.add(rankScore);
        }
    }

    public int getRankScore(int rank) {
        if(rank <= 0){
            return 0;
        }
        for (int i = 0; i < scoreList.size(); i++) {
            PeakStrongholdRankScore rankScore = scoreList.get(i);
            if(rank <= rankScore.getRank()){
                return rankScore.getScore();
            }
        }
        return 0;
    }
}
